package com.attendance.service.impl;

import com.attendance.common.CommonPage;
import com.attendance.common.CommonResult;
import com.attendance.mapper.GroupScoreMapper;
import com.attendance.pojo.GroupScore;
import com.attendance.pojo.Pages;
import com.attendance.service.GroupScoreService;
import com.attendance.vo.GroupScoreVo;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GroupScoreServiceImpl implements GroupScoreService {

    @Autowired
    private GroupScoreMapper groupScoreMapper;

    @Override
    public CommonResult selectAll(Pages pages) {
        PageHelper.startPage(pages.getPage(),pages.getNum());
        List<GroupScoreVo> list = groupScoreMapper.selectAll();
        if(list.size()==0){
            return CommonResult.failed("没有相关数据");
        }
        return CommonResult.success(CommonPage.restPage(list),"查询成功");
    }

    @Override
    public CommonResult selectByName(GroupScoreVo groupScoreVo,Pages pages) {
        PageHelper.startPage(pages.getPage(), pages.getNum());
        List<GroupScoreVo> list = groupScoreMapper.selectByName(groupScoreVo.getGroName(), groupScoreVo.getCouName());
        if(list.size()==0){
            return CommonResult.failed("没有相关数据");
        }
        return CommonResult.success(CommonPage.restPage(list),"查询成功");
    }

    @Override
    public CommonResult selectById(int gsId) {
        GroupScoreVo groupScoreVo = groupScoreMapper.selectById(gsId);
        if(groupScoreVo != null){
            return CommonResult.success(groupScoreVo,"查询详情成功");
        }else {
            return CommonResult.failed("查询详情失败");
        }
    }

    @Override
    public CommonResult addGroupScore(GroupScore groupScore) {
        int i = groupScoreMapper.addGroupScore(groupScore);
        if(i ==1){
            return CommonResult.success("新增成功");
        }else {
            return CommonResult.failed("新增失败");
        }
    }

    @Override
    public CommonResult updateGroupScore(GroupScore groupScore) {
        int i = groupScoreMapper.updateGroupScore(groupScore);
        if(i ==1){
            return CommonResult.success("修改成功");
        }else {
            return CommonResult.failed("修改失败");
        }
    }

    @Override
    public CommonResult modifyGroupScore(String gsId) {
        int i = groupScoreMapper.modifyGroupScore(gsId);
        if(i ==1){
            return CommonResult.success("修改成功");
        }else {
            return CommonResult.failed("修改失败");
        }
    }
}
